package us.feng.tinyspring.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import us.feng.tinyspring.aop.framework.AdvisedSupport;

/**
 * 基于JDK动态代理
 * 
 * @author feng
 *
 */
public class JdkAopProxy implements AopProxy,InvocationHandler{
	private AdvisedSupport advisedSupport;
	
	public void setAdvisedSupport(AdvisedSupport advisedSupport){
		this.advisedSupport=advisedSupport;
	}
	
	@Override
	public Object getProxy() {
		return Proxy.newProxyInstance(getClass().getClassLoader(), 
				new Class[] { advisedSupport.getTargetSource().getTargetClass() }, this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Object target=advisedSupport.getTargetSource();
		
		for(Advisor advisor:advisedSupport.getAdvisors()){
			// advisor.getAdvice();
		}
		Object rslt=method.invoke(target, args);
		return rslt;
	}

}
